﻿using Beetle;
using System;
using System.Runtime.CompilerServices;

internal class Class_u : Task
{
    private const string _field_a = "DEAD_CONNECTION";
    private Class_u_a _field_b;
    private Class_u_a _field_c;
    private int _field_d;

    public Class_u(int A_0)
    {
        this._field_d = A_0;
    }

    public void a(TcpChannel A_0)
    {
        lock (this)
        {
            Class_u_a _a = new Class_u_a();
            _a.b(A_0);
            _a.c(this._field_c);
            A_0._field_y = _a;
            if (this._field_c != null)
            {
                this._field_c.b(_a);
            }
            this._field_c = _a;
            if (this._field_b == null)
            {
                this._field_b = _a;
            }
        }
    }

    private void a(Class_u_a A_0)
    {
        while (A_0 != null)
        {
            A_0.c(null);
            if (A_0.c() != null)
            {
                A_0.c().CloseStatus = "DEAD_CONNECTION";
                A_0.c().Dispose();
                A_0.c()._field_y = null;
                A_0.b((TcpChannel) null);
            }
            A_0 = A_0.d();
        }
    }

    public void b(TcpChannel A_0)
    {
        lock (this)
        {
            Class_u_a _a = A_0._field_y;
            if (_a != null)
            {
                _a.e();
                if (_a != this._field_b)
                {
                    if (_a.b() != null)
                    {
                        _a.b().b(_a.d());
                    }
                    if (this._field_b != null)
                    {
                        _a.b(this._field_b);
                    }
                    _a.c(null);
                    this._field_b = _a;
                }
            }
        }
    }

    protected override void Execute()
    {
        Class_u_a _a = null;
        lock (this)
        {
            while ((this._field_c != null) && this._field_c.b(this._field_d))
            {
                _a = this._field_c;
                this._field_c = this._field_c.b();
            }
            if (this._field_c != null)
            {
                this._field_c.b((Class_u_a) null);
            }
            if (_a == this._field_b)
            {
                this._field_b = null;
            }
        }
        if (_a != null)
        {
            this.a(_a);
        }
    }

    internal class Class_u_a
    {
        public int _field_a = Environment.TickCount;
        [CompilerGenerated]
        private Class_u.Class_u_a _field_b;
        [CompilerGenerated]
        private Class_u.Class_u_a _field_c;
        [CompilerGenerated]
        private TcpChannel _field_d;

        [CompilerGenerated]
        public Class_u.Class_u_a b()
        {
            return this._field_b;
        }

        [CompilerGenerated]
        public void b(TcpChannel A_0)
        {
            this._field_d = A_0;
        }

        [CompilerGenerated]
        public void b(Class_u.Class_u_a A_0)
        {
            this._field_c = A_0;
        }

        public bool b(int A_0)
        {
            return ((Environment.TickCount - this._field_a) > A_0);
        }

        [CompilerGenerated]
        public TcpChannel c()
        {
            return this._field_d;
        }

        [CompilerGenerated]
        public void c(Class_u.Class_u_a A_0)
        {
            this._field_b = A_0;
        }

        [CompilerGenerated]
        public Class_u.Class_u_a d()
        {
            return this._field_c;
        }

        public void e()
        {
            this._field_a = Environment.TickCount;
        }
    }
}

